import pygame,player,rendering,enemy,time,gc
from mah_timeModule import mah_timer
import mapa
from entityManager import *
from vector import vector
class App:
    def __init__(self):
        gc.enable()
        self.running = True
        self.display = None
        self.frameCount = 0
    def init(self):
        pygame.init()
        self.display = pygame.display.set_mode((640,400), pygame.HWSURFACE)
        self.map = mapa.load_map("mapa",self.display)
        self.eM = entityManager(self.display,self.map,self.map.returnEntityList())
        self.p = self.eM.returnPlayer()
        self.running = True
    def event(self, event):
        if event.type == pygame.QUIT:
            self.running = False
            pygame.quit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_w:
                print "W"
                self.p.moveUp()
            if event.key == pygame.K_s:
                print "S"
                self.p.moveDown()
            if event.key == pygame.K_a:
                print "A"
                self.p.moveRight()
            if event.key == pygame.K_d:
                print "D"
                self.p.moveLeft()
            if event.key == pygame.K_SPACE:
                print "Attack"
                self.p.attack()
    def loop(self):
        pygame.display.flip()
    def cleanup(self):
        pygame.quit() 
    def execute(self):
        fps = mah_timer()
        if self.init() == False:
            self.running = False 
        while(self.running):
            self.map.redraw()
            for event in pygame.event.get():
                self.event(event)
            self.eM.update()
            self.loop()
        self.cleanup()
a = App()
a.init()
a.execute()
